//
//  SMPrdDetailHeadCell.m
//  ShoppingMall
//
//  Created by Demon on 2018/3/22.
//  Copyright © 2018年 Demon. All rights reserved.
//

#import "SMPrdDetailHeadCell.h"

@interface SMPrdDetailHeadCell ()

@property (weak, nonatomic) IBOutlet UIImageView *adImageView;
@property (weak, nonatomic) IBOutlet UILabel *prdTitleLb;
@property (weak, nonatomic) IBOutlet UILabel *quanhoujiaLb;
@property (weak, nonatomic) IBOutlet UILabel *salesNumLb;
@property (weak, nonatomic) IBOutlet UILabel *dianjiaLb;

@property (weak, nonatomic) IBOutlet UILabel *youhuiquanLb;
@property (nonatomic, strong) SMProductModel *prdModel;
@property (weak, nonatomic) IBOutlet UILabel *pingtaiLb;
@property (weak, nonatomic) IBOutlet UILabel *youhuiquanDateLb;
@property (weak, nonatomic) IBOutlet UIView *backGroundView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *imageViewHeight;

@end

@implementation SMPrdDetailHeadCell

- (void)setDetailHeadCellModel:(SMProductModel *)model {
    self.prdModel = model;
    @weakify(self)
    [self.adImageView sd_setImageWithURL:[NSURL URLWithString:model.mainimg] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        @strongify(self)
        float scale = image.size.width/image.size.height;
        self.imageViewHeight.constant = kScreenW/scale;
    }];
    self.prdTitleLb.text = model.title;
    self.pingtaiLb.text = model.pingtai;
    self.dianjiaLb.text = model.shangjia;
    self.youhuiquanDateLb.text = [NSString stringWithFormat:@"%@ 至 %@",model.cstarttime,model.cendtime];
    NSString *saleStr;
    if ([model.sales integerValue] < 10000) {
        saleStr = [NSString stringWithFormat:@"已售%@件",model.sales];
    } else {
        float num = [model.sales integerValue]/10000.0;
        saleStr = [NSString stringWithFormat:@"已售%.2f万件",num];
    }
    self.salesNumLb.text = saleStr;
    self.quanhoujiaLb.text = [NSString stringWithFormat:@"¥ %@",model.price];
    self.youhuiquanLb.text = model.coupon;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick)];
    [self.backGroundView addGestureRecognizer:tap];
}

- (void)tapClick {
    if (self.headCellClick) {
        self.headCellClick();
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
